package Decorator;

import javax.swing.*;
import java.awt.*;

public class MorriganAensland {
    public static void main(String[] args) {
        Morrigan m1 = new original();
        m1.display();;
        Morrigan m2 = new Succubus(m1);
        Morrigan m3 = new Girl(m1);
        m2.display();
        m3.display();
    }
}
//抽象构件：莫丽卡
interface Morrigan{
    public void display();
}
//具体构件角色：原身
class original extends JFrame implements Morrigan{
    private static final long serialVersionUID = 1L;
    private String t = "Morrigan0.jpg";
    public original(){
        super("《恶魔战士》中的莫丽卡.安斯兰");
    }
    public void setImage(String t){
        this.t = t;
    }
    @Override
    public void display()
    {
        this.setLayout(new FlowLayout());
        JLabel l1=new JLabel(new ImageIcon("src/Decorator/"+t));
        this.add(l1);
        this.pack();
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }
}
//抽象装饰角色：变形
class Changer implements Morrigan
{
    Morrigan m;
    public Changer(Morrigan m)
    {
        this.m=m;
    }
    public void display()
    {
        m.display();
    }
}
//具体装饰角色：女妖
class Succubus extends Changer
{
    public Succubus(Morrigan m)
    {
        super(m);
    }
    public void display()
    {
        setChanger();
        super.display();
    }
    public void setChanger()
    {
        ((original) super.m).setImage("Morrigan1.jpg");
    }
}
//具体装饰角色：少女
class Girl extends Changer
{
    public Girl(Morrigan m)
    {
        super(m);
    }
    public void display()
    {
        setChanger();
        super.display();
    }
    public void setChanger()
    {
        ((original) super.m).setImage("Morrigan2.jpg");
    }
}
